<template>
  <views class="article_list">
    <viewTitle :title="'文章列表'"></viewTitle>
    <div class="search">
      <el-form ref="form" label-width="auto" :inline="true">
        <el-form-item label="关键字:">
          <el-input type="text" clearable placeholder="请输入关键字" v-model="keywords"></el-input>
        </el-form-item>
        <el-form-item label="发布单位:">
            <el-input type="text" clearable placeholder="请输入发布单位" v-model="publish_unit"></el-input>
        </el-form-item>
        <el-form-item label="发布时间:">
          <el-date-picker
            v-model="create_time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="btn-area">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="reset">重置</el-button>
        <el-button type="warning"  v-if="$route.query.check.i" @click="add">新增</el-button>
      </div>
    </div>
    <div class="table_list">
      <el-table :data="tableList" style="width: 100%" border :header-cell-style="getRowClass">
        <el-table-column type="index" label="序号" width="100"></el-table-column>
        <el-table-column prop="title" label="内容名称" width="180"></el-table-column>
        <el-table-column prop="user_name" label="发布人" width="200"></el-table-column>
        <el-table-column prop="publish_unit" label="所属组织" width="300"></el-table-column>
        <el-table-column :formatter="(row)=>{return this.$moment(row.create_time * 1000).format('YYYY-MM-DD HH:mm:ss')}" label="发布时间" width="180"></el-table-column>
        <el-table-column :formatter="(row)=>{return this.$moment(row.modify_time * 1000).format('YYYY-MM-DD HH:mm:ss')}" label="最后修改时间" width="150"></el-table-column>
        <el-table-column fixed="right" label="操作" width="300">
          <template slot-scope="scope">
            <el-button type="success"  v-if="$route.query.check.q" @click="toDetail(scope.row)">详情</el-button>
            <el-button type="primary"  v-if="$route.query.check.m" @click="edit(scope.row)" icon="el-icon-edit">修改</el-button>
            <el-button type="danger"  v-if="$route.query.check.d" @click="deleted(scope.row)" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="prev, pager, next,sizes,total, jumper"
          @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
          @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>


<script>
export default {
  data() {
    return {
      keywords: "", // 编入时间
      create_time:[],
      publish_unit: "", // 组织
      // 组织列表
      tableList: [],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    };
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    // 获取数据
    getData() {
          this.$raxios.post(
            this.$mapapi.admin_lawList,{
            data:this.post_data
            }).then(res=>{
              if(res.code==200){
                this.tableList = res.data.list;
                this.pagination = res.data.pagination;
              }else{
                 this.tableList = [];
                 this.pagination = [];
	              this.$message.error(res.msg)
                 return;
              }
            }).catch(res=>{

            })          
    },
    // 去详情
    toDetail(row) {
      this.$toRoutePath({
        path: "/article_list/article_Detail",
        edit: true,
        query: { type: 1,article_id:row.article_id }
      });
    },
    // 重置
    reset() {
        this.create_time = [];
        this.keywords = '';
        this.publish_unit = '';
        this.getData()
    },
    // 修改
    edit(row) {
      this.$toRoutePath({
        path: "/article_list/article_Detail",
        edit: true,
        query: { type: 2,article_id:row.article_id}
      });
    },
    // 删除
    deleted(row) {
      this.$confirm("此操作将删除该文章, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
            let post_data={
              article_id:row.article_id
            }
            this.$raxios.post(
                this.$mapapi.admin_delArticle,
                {data:post_data}
            ).then(res=>{
              if(res.code==200){
                  this.$message({type: "success", message: "删除成功!"});
                this.getData();
              }else{
                 this.tableList = [];
                this.$message.error(res.msg);
                return;
              }
            })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 新增
    add() {
      this.$toRoutePath({
        path: "/article_list/article_Detail",
        edit: true,
        query: { type: 3 }
      });
    }
  },
  computed:{
      post_data(){
          let data = {};
          data.keywords = this.keywords;
          data.publish_unit = this.publish_unit;
          if(this.create_time && this.create_time.length){
              data.create_time_start = this.create_time[0]/1000;
              data.create_time_end = this.create_time[1]/1000;
          }
          data.pagination = this.pagination;
          return data;
      }
  },
  mounted() {
      this.getData();
  },
  created() {}
};
</script>





<style lang="less" :scope="true"  src="@/style/infomation_manager/article_list.less">
</style>
